#!/bin/sh
TLUIP=zenpixell3
EUDRBIP1=mvme6100
EUDRBIP2=mvme6200

export ROOTSYS=/usr/share/root/
export HOSTNAME=eudet

cd `dirname $0`/bin

echo 'STARTING DAQ'
echo '    Cleaning up first...'
killall RootMonitor.exe
killall TestDataCollector.exe
killall TLUProducer.exe
killall TLUControl.exe
ssh eudet@$TLUIP "killall TLUProducer.exe" &
ssh eudet@$TLUIP "killall TLUControl.exe" &
ssh eudet@$EUDRBIP1 "killall EUDRBProducer.exe" &
ssh eudet@$EUDRBIP2 "killall EUDRBProducer.exe" &
killall DEPFETProducerTCP.exe
killall euLog
killall euRun
sleep 1
echo '    Making sure all data files are properly writeprotected'
chmod a=r data/run*.raw
echo '\033[1;32;48m    ...Done!\033[0m'

echo '    Making sure TLU is accessible'
ssh root@$TLUIP "cd eudaq/bin; ./tlunoroot.exe"
sleep 1

echo '    Starting Subprocesses'

echo '        RunControl'
./euRun.app/Contents/MacOS/euRun -x 0 -y 0 -w 450 -g 450 &
sleep 3

echo '        LogCollector'
./euLog.app/Contents/MacOS/euLog -x 0 -y 450 -w 450 -g 550 &
sleep 3

echo '        DataCollector'
#./TestDataCollector.exe &
/usr/X11R6/bin/xterm -sb -sl 1000 -geom 80x10-500-440 -fn fixed -T "Data Collector" -e './TestDataCollector.exe' &
sleep 2

echo '        RootMonitor'
#/usr/X11R6/bin/xterm -sb -sl 1000 -geom 80x10-500-500 -fn fixed -T "Root Monitor" -e 'gdb ./RootMonitor.exe' &
./RootMonitor.exe -x 350 -y 0 -w 1330 -g 900 -r localhost &

echo '        TLU'
ssh -X -Y root@$TLUIP "(xterm -sb -sl 1000 -geom 80x10-500-290 -T 'TLU Producer' -e 'cd eudaq/bin/; ./TLUProducer.exe -r tcp://eudet:$RCPORT')" &

echo '        EUDRB 1'
ssh -X -Y eudet@$EUDRBIP1 "(xterm -sb -sl 1000 -geom 80x10-500-169 -fn fixed -T 'EUDRB Producer 1' -e 'cd eudaq/bin/; ./EUDRBProducer.exe -n EUDRB1 -r eudet | tee log')" &

sleep 1

#echo '        EUDRB 2'
#ssh -X -Y eudet@$EUDRBIP2 "(xterm -sb -sl 1000 -geom 80x10-500-20 -fn fixed -T 'EUDRB Producer 2' -e 'cd eudaq/bin/; ./EUDRBProducer.exe -n EUDRB2 -r eudet | tee log')" &




cd -
echo '\033[1;32;48m\t ...Done!\033[0m'
echo '\033[1;32;48mSTART OF DAQ COMPLETE\033[0m'

